import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_easyrefresh/material_header.dart';
import 'package:flutter_easyrefresh/material_footer.dart';

class GridviewRefresh extends StatefulWidget {
  @override
  _GridviewRefreshState createState() => _GridviewRefreshState();
}

class _GridviewRefreshState extends State<GridviewRefresh>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  List<String> addStrGrid = ["11", "22", "33", "44", "55", "66", "77", "88", "99", "00"];
  List<String> strGrid = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
  
  // GlobalKey<RefreshHeaderState> _headerKeyGrid =
  //     new GlobalKey<RefreshHeaderState>();
  // GlobalKey<RefreshFooterState> _footerKeyGrid =
  //     new GlobalKey<RefreshFooterState>();

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Gridviewåˆ·æ–°'),
          centerTitle: true,
        ),
        body: new EasyRefresh(
        //    refreshHeader: MaterialHeader(
        //   key: _headerKeyGrid,
        // ),
        // refreshFooter: MaterialFooter(
        //   key: _footerKeyGrid,
        // ),

          // refreshHeader: ClassicsHeader(
          //   key: _headerKeyGrid,
          //   refreshText: "pullToRefresh",
          //   refreshReadyText: "releaseToRefresh",
          //   refreshingText: "refreshing...",
          //   refreshedText: "refreshed",
          //   moreInfo: "updateAt",
          //   bgColor: Colors.transparent,
          //   textColor: Colors.black,
          // ),
          // refreshFooter: ClassicsFooter(
          //     key: _footerKeyGrid,
          //     loadHeight: 50.0,
          //     loadText: "pushToLoad",
          //     loadReadyText: "releaseToLoad",
          //     loadingText: "loading",
          //     loadedText: "loaded",
          //     noMoreText: "noMore",
          //     moreInfo: "updateAt",
          //     textColor: Colors.black,
          //     bgColor: Colors.transparent),
          child: new GridView.builder(
            //ListViewçš„Item
            itemCount: strGrid.length,
            gridDelegate:
                SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
            itemBuilder: (BuildContext context, int index) {
              return new Container(
                  height: 100.0,
                  child: Card(
                    child: new Center(
                      child: new Text(
                        strGrid[index],
                        style: new TextStyle(fontSize: 18.0),
                      ),
                    ),
                  ));
            },
          ),
          onRefresh: () async {
            await new Future.delayed(const Duration(seconds: 1), () {
              setState(() {
                strGrid.clear();
                //strGrid.addAll(addStrGrid);
                strGrid = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
              });
            });
          },
          onLoad: () async {
            await new Future.delayed(const Duration(seconds: 1), () {
              // if (strGrid.length < 20) {
                setState(() {
                  strGrid.addAll(addStrGrid);
                });
              // }
            });
          },
        ));
  }
}
